package com.example.fw;


import java.util.List;

import org.hibernate.Session;

public class HibernateHelper extends HelperBase{
	
	public HibernateHelper(ApplicationManager manager) {
		super(manager);
	}

	public Groups getGroups() {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		return  new Groups((List<GroupObject>) session.createQuery("from GroupObject").list());
	
	}
	public String getLastGroupId() {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		return  session.createQuery("select max(id) from GroupObject").uniqueResult().toString();
	}
	public Contacts getContacts() {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		return  new Contacts((List<ContactObject>) session.createQuery("from ContactObject").list());
	
	}
	public String getLastContactId() {
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        return session.createSQLQuery("SELECT AUTO_INCREMENT FROM information_schema.TABLES where TABLE_SCHEMA = 'addressbook' and TABLE_NAME = 'group_list' ").uniqueResult().toString();
}

}
